package com.jiuan.demo;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.jiuan.demo.api.ApiService;
import com.jiuan.retrofit.cache.FileCacheDaoDao;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.jiuan.retrofit.demo", appContext.getPackageName());
    }

    @Test
    public void testRetrofit() {
        Context context = InstrumentationRegistry.getTargetContext();
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl("http://api.vip.iemylife.com/api/")
                .cacheDao(new FileCacheDaoDao(context.getCacheDir().getAbsolutePath()))
                .build();
        ApiService apiService = retrofit.create(ApiService.class);
        try {
            String result = apiService.login("13022280815", "123456").execute().body().toString();
            System.out.println(result);
        } catch (IOException pE) {
            pE.printStackTrace();
        }
    }
}
